home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DeveloperStax.cpt / Developer Stack 1.2r / card_9721.txt < prev    next >
Text File  |  1989-02-26  |  6KB  |  170 lines

  1. -- card: 9721 from stack: in.2r
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 3837
  5. -- name: NewMenu
  6. ----- HyperTalk script -----
  7. on opencard  -- create the menus
  8.   --  keep the "handles" to the menus in these globals
  9.   global menu1, menu2
  10.   show menubar
  11.   put NewMenu("Beep","Once","Twice","(-","Boing/9") into menu1
  12.   if menu1 is 0 then answer("Unable to make menu 'BEEP'") with "Drat"
  13.   put NewMenu("Visual","Effect 1") into menu2
  14.   if menu2 is 0 then answer("Unable to make menu 'Visual'") with "Drat"
  15. end opencard
  16.  
  17. on closecard  --  delete the menus we've created using
  18.   --the globals saved in openStack
  19.   global menu1, menu2
  20.   put DeleteMenu(menu1) into menu1  --  clearing global for safety
  21.   put DeleteMenu(menu2) into menu2
  22.   hide menubar
  23. end closecard
  24.  
  25.  
  26. on idle  --  call ShowMenu every so often just in case our menus vanished
  27.   global menu1, menu2, lastTick
  28.   if (the ticks-lastTick)>120 then  --  gives better
  29.     -- performance than on every iteration
  30.     put the ticks into lastTick
  31.     ShowMenu(menu1)
  32.     ShowMenu(menu2)
  33.   end if
  34.   pass idle
  35. end idle
  36.  
  37.  
  38. on doMenu which  --  get our menu items from doMenu
  39.   -- before HyperCard does...
  40.   global menu1, menu2  -- for CheckMenu and
  41.   -- EnableMenu below
  42.   if which is "Once" then
  43.     beep 1
  44.     CheckMenu menu1,1,true
  45.   else if which is "Twice" then
  46.     beep 1
  47.     wait 4
  48.     beep 1
  49.     CheckMenu menu1,2,true
  50.   else if which is "Boing" then
  51.     play "Boing"
  52.     CheckMenu menu1,4,true
  53.   else if which is "Effect 1" then
  54.     push card
  55.     visual effect dissolve to black
  56.     pop card
  57.     EnableMenu menu2,1,false
  58.   else pass doMenu  --  Remember to pass on menu commands you don't trap!
  59. end doMenu
  60.  
  61.  
  62.  
  63. -- part contents for background part 5
  64. ----- text -----
  65. NewMenu
  66.  
  67. -- part contents for background part 10
  68. ----- text -----
  69. 3
  70.  
  71. -- part contents for background part 6
  72. ----- text -----
  73.  
  74. NewMenu allows you to add your own menus to a HyperCard stack.  You may have up to eight menus with up to 15 items per menu.  
  75.  
  76. When you change userLevels, or select paint tools, or do anything to cause HyperCard to change the menu bar--your new menu will be erased from the menu bar.  It is NOT gone from memory, just from the menu bar.  To have it replaced automatically do the "on idle" routine shown below.  This will make sure your menu is showing whenever you are in browse mode 
  77. (on idle is not called when you're in button, field, or paint tools mode).
  78.  
  79. All this would generally be done in a stack's script as follows:
  80.  
  81. on openStack  -- create the menus
  82.   --  keep the "handles" to the menus in these globals
  83.   global menu1, menu2  
  84.   put NewMenu("Beep","Once","Twice","(-","Boing/9")   
  85.          into menu1
  86.   if menu1 is 0 then answer("Unable to make menu 'BEEP'")           
  87.         with "Drat"
  88.   put NewMenu("Visual","Effect 1") into menu2
  89.   if menu2 is 0 then answer("Unable to make menu 
  90.         'Visual'") with "Drat"
  91. end openStack
  92.  
  93.  
  94. on closeStack  --  delete the menus we've created using 
  95.                        --the globals saved in openStack
  96.   global menu1, menu2
  97.   put DeleteMenu(menu1) into menu1  --  clearing global
  98.                                                          --  for safety
  99.   put DeleteMenu(menu2) into menu2
  100. end closeStack
  101.  
  102.  
  103. on idle  --  call ShowMenu every so often just in case 
  104.             --  our menus vanished
  105.   global menu1, menu2, lastTick
  106.   if (the ticks-lastTick)>120 then  --  gives better
  107.                            -- performance than on every iteration
  108.     put the ticks into lastTick
  109.     ShowMenu(menu1)
  110.     ShowMenu(menu2)
  111.   end if
  112.   pass idle
  113. end idle
  114.  
  115.  
  116. on doMenu which  --  get our menu items from doMenu 
  117.                            -- before HyperCard does...
  118.   global menu1, menu2  -- for CheckMenu and 
  119.                                    -- EnableMenu below
  120.   if which is "Once" then
  121.     beep 1
  122.     CheckMenu menu1,1,true
  123.   else if which is "Twice" then
  124.     beep 1
  125.     wait 4
  126.     beep 1
  127.     CheckMenu menu1,2,true 
  128.   else if which is "Boing" then
  129.     play "Boing"
  130.     CheckMenu menu1,4,true 
  131.   else if which is "Effect 1" then
  132.     push card
  133.     visual effect dissolve to black
  134.     pop card
  135.     EnableMenu menu2,1,false 
  136.     else pass doMenu  --  Remember to pass on menu 
  137.                                 --  commands you don't trap!
  138. end doMenu
  139.  
  140.  
  141. Notice that if you want the menu to appear for all cards in the stack, you would place the NewMenu function in the stack's script and install it "on openStack" and remove it 
  142. "on closeStack".  If you wanted a menu to appear only for a certain background, the commands would be in that background's script and done "on openBackground" and "on closeBackground".  And the commands to make a menu to appear only on a certain card would be done in that card's script "on openCard"/"on closeCard".
  143.  
  144. •••
  145.  
  146. All the credit, (even the descriptions above) go to the creator of this ingenious XFCN:
  147.  
  148. Nine to Five Software Company
  149. P.O. Box 915
  150. Greenwood, IN  46142
  151. (317) 887-2154
  152. & Michael Long
  153.  
  154. See also CheckMenu*, EnableMenu*, DeleteMenu*, and ChangeMenu*.
  155.  
  156.  
  157. -- part contents for background part 7
  158. ----- text -----
  159. Syntax:
  160.  
  161. NewMenu(<"Title">,<"Item1",Item2",...,"Item n">)
  162.  
  163. Returns a reference number to the menu you just installed.  You MUST have this number to delete or make changes to the menu later on!  
  164.  
  165.  
  166. "Title" is the name that will be put into the menubar.
  167.  
  168. "Item1" through "Item n" are the names of the items in the pull down part of the menu.
  169.  
  170. Add an item like "(-" to insert a divider line between menu options.  You may also end items with a slash letter (as is "An item/I") to add command keys.